﻿using DomainNameServer;
using DomainNameServer.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DSVISUAL.LocalDNS.Views
{
    public partial class AddDomainForm : Form, IAcceptableFormBody
    {
        public AddDomainForm()
        {
            InitializeComponent();
            this.Shown += AddDomainForm_Shown;

        }

        private void AddDomainForm_Shown(object sender, EventArgs e)
        {
            this.textBox1.Focus();
        }

        public void Accept(AcceptFormOption option)
        {
            if (string.IsNullOrEmpty(this.textBox1.Text))
            {
                MessageBox.Show(this, "should enter a valid domain first.");
            }
            else
            {
                try
                {
                    DomainManager.Instance.AddDomain(this.textBox1.Text);
                    this.DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    option.KeepWindow = true;
                    MessageBox.Show(this, ex.Message);
                }
            }
        }

        public void Cancel()
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
